from django.contrib.auth import logout
from django.shortcuts import render, redirect

# Create your views here.
from django.views import View



# class IndexView(View):
#     def get(self,request):
#         return render(request,'index.html')
from contents.models import ContentCategory
from goods.models import GoodsChannel
from my_taobao.untils.my_category import get_categories


class LoginOut(View):
    def get(self,request):
        logout(request)

        response=redirect('/')
        response.delete_cookie('username')
        return response

#1, 展示首页
class IndexView(View):
    def get(self,request):

        # #1, 定义好空字典
        # categories = {}
        #1,获取分类数据
        categories = get_categories()

        #2, 查询所有的频道




        # 4,查询广告分类
        content_categories = ContentCategory.objects.order_by("id").all()
        contents = {}
        for content_category in content_categories:
            contents[content_category.key] = content_category.content_set.all()

        # 5, 返回数据,渲染页面
        context = {
            "categories": categories,
            "contents": contents
        }
        return render(request, 'index.html', context=context)


#3, 获取网站logo
class LoGoView(View):
    def get(self,request):
        return redirect("/static/favicon.ico")